<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../plugins/css/index.css">
    <script src="../../../plugins/js/request.js"></script>
    <script type="text/javascript" src="../plugins/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="../plugins/js/tags/api.js"></script>
    <title>标签</title>
</head>

<body>
<!-- 导航 -->
<div id="tags">
<nav class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">Blog</h2>
            <a href="index.html" class="m-item item m-mobile-hide"><i class="home icon"></i> 首页</a>
            <a href="types.html" class="  m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
            <a href="tags.html" class=" active m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <a href="archives.html" class="m-item item m-mobile-hide"><i class="clone icon"></i>归档</a>
            <a href="about.html" class="m-item item m-mobile-hide"><i class="info icon"></i>关于我</a>
            <div class=" m-item right item m-mobile-hide">
                <div class="ui icon  input">
                    <input type="text" placeholder="搜索.......">
                    <i class="search link icon"></i>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-top-right m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!-- 内容 -->
<div class="m-container-small m-padded-tb-large">
    <div class="ui container">
        <!-- header -->
        <div class="ui top attached segment">
            <div class="ui middle aligned two column grid">
                <div class="column">
                    <h3 class="ui teal header">标签</h3>
                </div>
                <div class="right aligned column">
                    共 <h2 class="ui orange header m-inline-block">{{totals}}</h2> 个
                </div>
            </div>
            <!-- 分类标签 -->
            <div class="ui attached segment m-padded-tb-large">
                <a href="#" target="_blank" class="ui teal basic left pointing large label m-margin-tb-tiny" v-for="(item,index) in tag" @click="jump(item.id)">
                    {{item.name}}
                    <div class="detail">{{item.count}}</div>
                </a>

            </div>


            <!-- 博客列表 -->
            <div class="ui top attached  teal segment" v-for="(item,index) in blog">
                <div class="ui padded vertical segment m-padded-tb-big m-mobile-lr-clea">
                    <div class="ui middle aligned mobile reversed stackable grid">
                        <div class="eleven wide column ">
                            <h3 class="ui header">{{item.title}}</h3>
                            <p class="m-text">{{item.description}}
                            </p>
                            <div class="ui stackable grid">
                                <div class="row">
                                    <div class="eleven wide column">
                                        <div class="ui  mini horizontal link list">
                                            <div class="item">
                                                <img :src="item.avatar" alt=""
                                                     class="ui avatar image">
                                                <div class="content">
                                                    <div class="header">{{item.name}}</div>
                                                </div>
                                            </div>
                                            <div class="item">
                                                <i class="calendar icon"></i> {{item.updateTime}}
                                            </div>
                                            <div class="item">
                                                <i class="eye icon"></i> {{item.views}}
                                            </div>
                                        </div>
                                    </div>
                                    <div class="right aligned five wide column">
                                        <a href="#" target="_blank"
                                           class="ui teal basic label m-padded-tiny m-text-thin">{{item.type}}</a>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="column">
                                        <a href="#" class="ui basic teal left pointing label m-padded-mini m-text-thin">{{item.tag}}</a>
                                    </div>
                                </div>
                            </div>

                        </div>

                        <div class="five wide column">
                            <a href="#" target="-blank">
                                <img :src="item.firstPicture"alt="" class="ui rounded image">
                            </a>
                        </div>
                    </div>
                </div>


            </div>
            <!-- footer -->
            <div class="ui bottom attached segment">
                <div class="ui middle aligned two column grid">
                    <div class="column">
                        <a href="#" class="ui mini teal basic button">上一页</a>
                    </div>
                    <div class="right aligned column">
                        <a href="#" class="ui mini teal basic button">下一页</a>
                    </div>
                </div>
            </div>
        </div>
        </div>
        </div>

        <!-- 底部footer -->
    <footer class="ui inverted vertical segment m-padded-tb-massive">
        <div class="ui center aligned container" >
            <div class="ui inverted divided stackable grid">
                <div class="three wide column">
                    <img src="https://cdn.seovx.com/ha/?mom=302" class="ui rounded image" alt="" style="width: 120px;">
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header">最新博客</h4>
                    <div class="ui inverted link list"  v-for="(item,index) in blog.slice(0,3)">
                        <a href="#" class="item">{{item.title}}</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">用户故事</a>
                        <a href="#" class="item">用户故事</a>
                        <a href="#" class="item">用户故事</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header">最新博客</h4>
                    <p>一段内容</p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="m-text-spaced m-text-lined">BV1nE411r7TF?p=4&spm_id_from=pageDriver&vd_s</p>
        </div>

</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 官网提供的 axios 在线地址 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
        <script>
            $('.menu.toggle').click(function () {
                $('.m-item').toggleClass('m-mobile-hide');
            });

            new Vue({
                el:"#tags",
                data() {
                    return {
                        page: 1,
                        pageSize: 5,
                        blog:[],
                        type:[],
                        tag:[],
                        totals:'',
                        TagId:'',
                        tagId:'',
                        kind:'no',

                    }
                },
                created(){
                    this.TagId=requestUrlParam("id");
                    if (this.TagId){
                        this.kind='yes'

                    }this.init()
                    this. types()
                },
                methods:{
                    // aixos 会返回一个Promise对象
                    // async 和 await 基于 promise 的。
                    //   使用 async 的函数将会始终返回一个 promise 对象
                    //   await 关键字只能放到async 函数里面
                    async init() {

                        if (this.kind==='no'){
                            const params = {
                                page: this.page,
                                pageSize: this.pageSize,

                            }
                            await getTag(params).then(res => {
                                console.log(res.data)
                                if (String(res.data.code) === '1') {
                                    console.log(res.data.data.total)

                                    this.blog =res.data.data.records
                                    console.log(this.blog)

                                }
                            }).catch(err => {
                                alert("cuowu")
                            })}else{
                            const params = {
                                page: this.page,
                                pageSize: this.pageSize,
                                id:this.TagId
                            }
                            await getIdTag(params).then(res => {
                                console.log(res.data)
                                if (String(res.data.code) === '1') {
                                    console.log(res.data.data.total)

                                    this.blog =res.data.data.records
                                    console.log(this.blog)

                                }
                            }).catch(err => {
                                alert("cuowu")
                            })
                        }

                    },
                    async types(){
                        const params = {
                            page: this.page,
                            pageSize: 20,

                        }
                        await Tags(params).then(res => {
                            console.log(res.data)
                            if (String(res.data.code) === '1') {
                                this.totals=res.data.data.total
                                this.tag =res.data.data.records
                                console.log(this.tag)

                            }
                        }).catch(err => {
                            alert("cuowu")
                        })

                    },
                    jump(id){
                        window.location.href="tags.html?id="+id;
                    }

                }
            })
        </script>
</body>

</html>